home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / flex_247.zip / flex_247 / gen.c < prev    next >
C/C++ Source or Header  |  1994-08-03  |  33KB  |  1,462 lines

  1. /* gen - actual generation (writing) of flex scanners */
  2.  
  3. /*-
  4.  * Copyright (c) 1990 The Regents of the University of California.
  5.  * All rights reserved.
  6.  *
  7.  * This code is derived from software contributed to Berkeley by
  8.  * Vern Paxson.
  9.  * 
  10.  * The United States Government has rights in this work pursuant
  11.  * to contract no. DE-AC03-76SF00098 between the United States
  12.  * Department of Energy and the University of California.
  13.  *
  14.  * Redistribution and use in source and binary forms are permitted provided
  15.  * that: (1) source distributions retain this entire copyright notice and
  16.  * comment, and (2) distributions including binaries display the following
  17.  * acknowledgement:  ``This product includes software developed by the
  18.  * University of California, Berkeley and its contributors'' in the
  19.  * documentation or other materials provided with the distribution and in
  20.  * all advertising materials mentioning features or use of this software.
  21.  * Neither the name of the University nor the names of its contributors may
  22.  * be used to endorse or promote products derived from this software without
  23.  * specific prior written permission.
  24.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  25.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  26.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27.  */
  28.  
  29. /* $Header: /home/daffy/u0/vern/flex/flex-2.4.7/RCS/gen.c,v 1.3 94/08/03 11:37:45 vern Exp $ */
  30.  
  31. #include "flexdef.h"
  32.  
  33.  
  34. /* declare functions that have forward references */
  35.  
  36. void gen_next_state PROTO((int));
  37. void genecs PROTO((void));
  38. void indent_put2s PROTO((char [], char []));
  39. void indent_puts PROTO((char []));
  40.  
  41.  
  42. static int indent_level = 0; /* each level is 8 spaces */
  43.  
  44. #define indent_up() (++indent_level)
  45. #define indent_down() (--indent_level)
  46. #define set_indent(indent_val) indent_level = indent_val
  47.  
  48. /* Almost everything is done in terms of arrays starting at 1, so provide
  49.  * a null entry for the zero element of all C arrays.  (The exception
  50.  * to this is that the fast table representation generally uses the
  51.  * 0 elements of its arrays, too.)
  52.  */
  53. static char C_int_decl[] = "static const int %s[%d] =\n    {   0,\n";
  54. static char C_short_decl[] = "static const short int %s[%d] =\n    {   0,\n";
  55. static char C_long_decl[] = "static const long int %s[%d] =\n    {   0,\n";
  56. static char C_state_decl[] =
  57.     "static const yy_state_type %s[%d] =\n    {   0,\n";
  58.  
  59.  
  60. /* Indent to the current level. */
  61.  
  62. void do_indent()
  63.     {
  64.     register int i = indent_level * 8;
  65.  
  66.     while ( i >= 8 )
  67.         {
  68.         putchar( '\t' );
  69.         i -= 8;
  70.         }
  71.  
  72.     while ( i > 0 )
  73.         {
  74.         putchar( ' ' );
  75.         --i;
  76.         }
  77.     }
  78.  
  79.  
  80. /* Generate the code to keep backing-up information. */
  81.  
  82. void gen_backing_up()
  83.     {
  84.     if ( reject || num_backing_up == 0 )
  85.         return;
  86.  
  87.     if ( fullspd )
  88.         indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
  89.     else
  90.         indent_puts( "if ( yy_accept[yy_current_state] )" );
  91.  
  92.     indent_up();
  93.     indent_puts( "{" );
  94.     indent_puts( "yy_last_accepting_state = yy_current_state;" );
  95.     indent_puts( "yy_last_accepting_cpos = yy_cp;" );
  96.     indent_puts( "}" );
  97.     indent_down();
  98.     }
  99.  
  100.  
  101. /* Generate the code to perform the backing up. */
  102.  
  103. void gen_bu_action()
  104.     {
  105.     if ( reject || num_backing_up == 0 )
  106.         return;
  107.  
  108.     set_indent( 3 );
  109.  
  110.     indent_puts( "case 0: /* must back up */" );
  111.     indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
  112.     indent_puts( "*yy_cp = yy_hold_char;" );
  113.  
  114.     if ( fullspd || fulltbl )
  115.         indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
  116.     else
  117.         /* Backing-up info for compressed tables is taken \after/
  118.          * yy_cp has been incremented for the next state.
  119.          */
  120.         indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  121.  
  122.     indent_puts( "yy_current_state = yy_last_accepting_state;" );
  123.     indent_puts( "goto yy_find_action;" );
  124.     putchar( '\n' );
  125.  
  126.     set_indent( 0 );
  127.     }
  128.  
  129.  
  130. /* genctbl - generates full speed compressed transition table */
  131.  
  132. void genctbl()
  133.     {
  134.     register int i;
  135.     int end_of_buffer_action = num_rules + 1;
  136.  
  137.     /* Table of verify for transition and offset to next state. */
  138.     printf( "static const struct yy_trans_info yy_transition[%d] =\n",
  139.         tblend + numecs + 1 );
  140.     printf( "    {\n" );
  141.  
  142.     /* We want the transition to be represented as the offset to the
  143.      * next state, not the actual state number, which is what it currently
  144.      * is.  The offset is base[nxt[i]] - (base of current state)].  That's
  145.      * just the difference between the starting points of the two involved
  146.      * states (to - from).
  147.      *
  148.      * First, though, we need to find some way to put in our end-of-buffer
  149.      * flags and states.  We do this by making a state with absolutely no
  150.      * transitions.  We put it at the end of the table.
  151.      */
  152.  
  153.     /* We need to have room in nxt/chk for two more slots: One for the
  154.      * action and one for the end-of-buffer transition.  We now *assume*
  155.      * that we're guaranteed the only character we'll try to index this
  156.      * nxt/chk pair with is EOB, i.e., 0, so we don't have to make sure
  157.      * there's room for jam entries for other characters.
  158.      */
  159.  
  160.     while ( tblend + 2 >= current_max_xpairs )
  161.         expand_nxt_chk();
  162.  
  163.     while ( lastdfa + 1 >= current_max_dfas )
  164.         increase_max_dfas();
  165.  
  166.     base[lastdfa + 1] = tblend + 2;
  167.     nxt[tblend + 1] = end_of_buffer_action;
  168.     chk[tblend + 1] = numecs + 1;
  169.     chk[tblend + 2] = 1; /* anything but EOB */
  170.  
  171.     /* So that "make test" won't show arb. differences. */
  172.     nxt[tblend + 2] = 0;
  173.  
  174.     /* Make sure every state has an end-of-buffer transition and an
  175.      * action #.
  176.      */
  177.     for ( i = 0; i <= lastdfa; ++i )
  178.         {
  179.         int anum = dfaacc[i].dfaacc_state;
  180.         int offset = base[i];
  181.  
  182.         chk[offset] = EOB_POSITION;
  183.         chk[offset - 1] = ACTION_POSITION;
  184.         nxt[offset - 1] = anum;    /* action number */
  185.         }
  186.  
  187.     for ( i = 0; i <= tblend; ++i )
  188.         {
  189.         if ( chk[i] == EOB_POSITION )
  190.             transition_struct_out( 0, base[lastdfa + 1] - i );
  191.  
  192.         else if ( chk[i] == ACTION_POSITION )
  193.             transition_struct_out( 0, nxt[i] );
  194.  
  195.         else if ( chk[i] > numecs || chk[i] == 0 )
  196.             transition_struct_out( 0, 0 );    /* unused slot */
  197.  
  198.         else    /* verify, transition */
  199.             transition_struct_out( chk[i],
  200.                         base[nxt[i]] - (i - chk[i]) );
  201.         }
  202.  
  203.  
  204.     /* Here's the final, end-of-buffer state. */
  205.     transition_struct_out( chk[tblend + 1], nxt[tblend + 1] );
  206.     transition_struct_out( chk[tblend + 2], nxt[tblend + 2] );
  207.  
  208.     printf( "    };\n" );
  209.     printf( "\n" );
  210.  
  211.     /* Table of pointers to start states. */
  212.     printf(
  213.     "static const struct yy_trans_info *yy_start_state_list[%d] =\n",
  214.         lastsc * 2 + 1 );
  215.     printf( "    {\n" );    /* } so vi doesn't get confused */
  216.  
  217.     for ( i = 0; i <= lastsc * 2; ++i )
  218.         printf( "    &yy_transition[%d],\n", base[i] );
  219.  
  220.     dataend();
  221.  
  222.     if ( useecs )
  223.         genecs();
  224.     }
  225.  
  226.  
  227. /* Generate equivalence-class tables. */
  228.  
  229. void genecs()
  230.     {
  231.     Char clower();
  232.     register int i, j;
  233.     int numrows;
  234.  
  235.     printf( C_int_decl, "yy_ec", csize );
  236.  
  237.     for ( i = 1; i < csize; ++i )
  238.         {
  239.         if ( caseins && (i >= 'A') && (i <= 'Z') )
  240.             ecgroup[i] = ecgroup[clower( i )];
  241.  
  242.         ecgroup[i] = ABS( ecgroup[i] );
  243.         mkdata( ecgroup[i] );
  244.         }
  245.  
  246.     dataend();
  247.  
  248.     if ( trace )
  249.         {
  250.         fputs( "\n\nEquivalence Classes:\n\n", stderr );
  251.  
  252.         numrows = csize / 8;
  253.  
  254.         for ( j = 0; j < numrows; ++j )
  255.             {
  256.             for ( i = j; i < csize; i = i + numrows )
  257.                 {
  258.                 fprintf( stderr, "%4s = %-2d",
  259.                     readable_form( i ), ecgroup[i] );
  260.  
  261.                 putc( ' ', stderr );
  262.                 }
  263.  
  264.             putc( '\n', stderr );
  265.             }
  266.         }
  267.     }
  268.  
  269.  
  270. /* Generate the code to find the action number. */
  271.  
  272. void gen_find_action()
  273.     {
  274.     if ( fullspd )
  275.         indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
  276.  
  277.     else if ( fulltbl )
  278.         indent_puts( "yy_act = yy_accept[yy_current_state];" );
  279.  
  280.     else if ( reject )
  281.         {
  282.         indent_puts( "yy_current_state = *--yy_state_ptr;" );
  283.         indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  284.  
  285.         puts(
  286.         "find_rule: /* we branch to this label when backing up */" );
  287.  
  288.         indent_puts(
  289.         "for ( ; ; ) /* until we find what rule we matched */" );
  290.  
  291.         indent_up();
  292.  
  293.         indent_puts( "{" );
  294.  
  295.         indent_puts(
  296.         "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
  297.         indent_up();
  298.         indent_puts( "{" );
  299.         indent_puts( "yy_act = yy_acclist[yy_lp];" );
  300.  
  301.         if ( variable_trailing_context_rules )
  302.             {
  303.             indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
  304.             indent_puts( "     yy_looking_for_trail_begin )" );
  305.             indent_up();
  306.             indent_puts( "{" );
  307.  
  308.             indent_puts(
  309.                 "if ( yy_act == yy_looking_for_trail_begin )" );
  310.             indent_up();
  311.             indent_puts( "{" );
  312.             indent_puts( "yy_looking_for_trail_begin = 0;" );
  313.             indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
  314.             indent_puts( "break;" );
  315.             indent_puts( "}" );
  316.             indent_down();
  317.  
  318.             indent_puts( "}" );
  319.             indent_down();
  320.  
  321.             indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
  322.             indent_up();
  323.             indent_puts( "{" );
  324.             indent_puts(
  325.         "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
  326.             indent_puts(
  327.         "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
  328.  
  329.             if ( real_reject )
  330.                 {
  331.                 /* Remember matched text in case we back up
  332.                  * due to REJECT.
  333.                  */
  334.                 indent_puts( "yy_full_match = yy_cp;" );
  335.                 indent_puts( "yy_full_state = yy_state_ptr;" );
  336.                 indent_puts( "yy_full_lp = yy_lp;" );
  337.                 }
  338.  
  339.             indent_puts( "}" );
  340.             indent_down();
  341.  
  342.             indent_puts( "else" );
  343.             indent_up();
  344.             indent_puts( "{" );
  345.             indent_puts( "yy_full_match = yy_cp;" );
  346.             indent_puts( "yy_full_state = yy_state_ptr;" );
  347.             indent_puts( "yy_full_lp = yy_lp;" );
  348.             indent_puts( "break;" );
  349.             indent_puts( "}" );
  350.             indent_down();
  351.  
  352.             indent_puts( "++yy_lp;" );
  353.             indent_puts( "goto find_rule;" );
  354.             }
  355.  
  356.         else
  357.         {
  358.         /* Remember matched text in case we back up due to trailing
  359.          * context plus REJECT.
  360.          */
  361.         indent_up();
  362.         indent_puts( "{" );
  363.         indent_puts( "yy_full_match = yy_cp;" );
  364.         indent_puts( "break;" );
  365.         indent_puts( "}" );
  366.         indent_down();
  367.         }
  368.  
  369.         indent_puts( "}" );
  370.         indent_down();
  371.  
  372.         indent_puts( "--yy_cp;" );
  373.  
  374.         /* We could consolidate the following two lines with those at
  375.          * the beginning, but at the cost of complaints that we're
  376.          * branching inside a loop.
  377.          */
  378.         indent_puts( "yy_current_state = *--yy_state_ptr;" );
  379.         indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  380.  
  381.         indent_puts( "}" );
  382.  
  383.         indent_down();
  384.         }
  385.  
  386.     else
  387.         /* compressed */
  388.         indent_puts( "yy_act = yy_accept[yy_current_state];" );
  389.     }
  390.  
  391.  
  392. /* genftbl - generates full transition table */
  393.  
  394. void genftbl()
  395.     {
  396.     register int i;
  397.     int end_of_buffer_action = num_rules + 1;
  398.  
  399.     printf( long_align ? C_long_decl : C_short_decl,
  400.         "yy_accept", lastdfa + 1 );
  401.  
  402.     dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  403.  
  404.     for ( i = 1; i <= lastdfa; ++i )
  405.         {
  406.         register int anum = dfaacc[i].dfaacc_state;
  407.  
  408.         mkdata( anum );
  409.  
  410.         if ( trace && anum )
  411.             fprintf( stderr, "state # %d accepts: [%d]\n",
  412.                 i, anum );
  413.         }
  414.  
  415.     dataend();
  416.  
  417.     if ( useecs )
  418.         genecs();
  419.  
  420.     /* Don't have to dump the actual full table entries - they were
  421.      * created on-the-fly.
  422.      */
  423.     }
  424.  
  425.  
  426. /* Generate the code to find the next compressed-table state. */
  427.  
  428. void gen_next_compressed_state( char_map )
  429. char *char_map;
  430.     {
  431.     indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
  432.  
  433.     /* Save the backing-up info \before/ computing the next state
  434.      * because we always compute one more state than needed - we
  435.      * always proceed until we reach a jam state
  436.      */
  437.     gen_backing_up();
  438.  
  439.     indent_puts(
  440. "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
  441.     indent_up();
  442.     indent_puts( "{" );
  443.     indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" );
  444.  
  445.     if ( usemecs )
  446.         {
  447.         /* We've arrange it so that templates are never chained
  448.          * to one another.  This means we can afford to make a
  449.          * very simple test to see if we need to convert to
  450.          * yy_c's meta-equivalence class without worrying
  451.          * about erroneously looking up the meta-equivalence
  452.          * class twice
  453.          */
  454.         do_indent();
  455.  
  456.         /* lastdfa + 2 is the beginning of the templates */
  457.         printf( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
  458.  
  459.         indent_up();
  460.         indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" );
  461.         indent_down();
  462.         }
  463.  
  464.     indent_puts( "}" );
  465.     indent_down();
  466.  
  467.     indent_puts(
  468. "yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" );
  469.     }
  470.  
  471.  
  472. /* Generate the code to find the next match. */
  473.  
  474. void gen_next_match()
  475.     {
  476.     /* NOTE - changes in here should be reflected in gen_next_state() and
  477.      * gen_NUL_trans().
  478.      */
  479.     char *char_map = useecs ?
  480.                 "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
  481.                 "YY_SC_TO_UI(*yy_cp)";
  482.  
  483.     char *char_map_2 = useecs ?
  484.                 "yy_ec[YY_SC_TO_UI(*++yy_cp)]" :
  485.                 "YY_SC_TO_UI(*++yy_cp)";
  486.  
  487.     if ( fulltbl )
  488.         {
  489.         indent_put2s(
  490.     "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
  491.                 char_map );
  492.  
  493.         indent_up();
  494.  
  495.         if ( num_backing_up > 0 )
  496.             {
  497.             indent_puts( "{" );    /* } for vi */
  498.             gen_backing_up();
  499.             putchar( '\n' );
  500.             }
  501.  
  502.         indent_puts( "++yy_cp;" );
  503.  
  504.         if ( num_backing_up > 0 )
  505.             /* { for vi */
  506.             indent_puts( "}" );
  507.  
  508.         indent_down();
  509.  
  510.         putchar( '\n' );
  511.         indent_puts( "yy_current_state = -yy_current_state;" );
  512.         }
  513.  
  514.     else if ( fullspd )
  515.         {
  516.         indent_puts( "{" );    /* } for vi */
  517.         indent_puts(
  518.         "register const struct yy_trans_info *yy_trans_info;\n" );
  519.         indent_puts( "register YY_CHAR yy_c;\n" );
  520.         indent_put2s( "for ( yy_c = %s;", char_map );
  521.         indent_puts(
  522.     "      (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" );
  523.         indent_puts( "yy_verify == yy_c;" );
  524.         indent_put2s( "      yy_c = %s )", char_map_2 );
  525.  
  526.         indent_up();
  527.  
  528.         if ( num_backing_up > 0 )
  529.             indent_puts( "{" );    /* } for vi */
  530.  
  531.         indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  532.  
  533.         if ( num_backing_up > 0 )
  534.             {
  535.             putchar( '\n' );
  536.             gen_backing_up();    /* { for vi */
  537.             indent_puts( "}" );
  538.             }
  539.  
  540.         indent_down();    /* { for vi */
  541.         indent_puts( "}" );
  542.         }
  543.  
  544.     else
  545.         { /* compressed */
  546.         indent_puts( "do" );
  547.  
  548.         indent_up();
  549.         indent_puts( "{" );    /* } for vi */
  550.  
  551.         gen_next_state( false );
  552.  
  553.         indent_puts( "++yy_cp;" );
  554.  
  555.         /* { for vi */
  556.         indent_puts( "}" );
  557.         indent_down();
  558.  
  559.         do_indent();
  560.  
  561.         if ( interactive )
  562.             printf( "while ( yy_base[yy_current_state] != %d );\n",
  563.                 jambase );
  564.         else
  565.             printf( "while ( yy_current_state != %d );\n",
  566.                 jamstate );
  567.  
  568.         if ( ! reject && ! interactive )
  569.             {
  570.             /* Do the guaranteed-needed backing up to figure out
  571.              * the match.
  572.              */
  573.             indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  574.             indent_puts(
  575.                 "yy_current_state = yy_last_accepting_state;" );
  576.             }
  577.         }
  578.     }
  579.  
  580.  
  581. /* Generate the code to find the next state. */
  582.  
  583. void gen_next_state( worry_about_NULs )
  584. int worry_about_NULs;
  585.     { /* NOTE - changes in here should be reflected in get_next_match() */
  586.     char char_map[256];
  587.  
  588.     if ( worry_about_NULs && ! nultrans )
  589.         {
  590.         if ( useecs )
  591.             (void) sprintf( char_map,
  592.                 "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
  593.                     NUL_ec );
  594.         else
  595.             (void) sprintf( char_map,
  596.                 "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec );
  597.         }
  598.  
  599.     else
  600.         strcpy( char_map, useecs ? "yy_ec[YY_SC_TO_UI(*yy_cp)]" :
  601.                        "YY_SC_TO_UI(*yy_cp)" );
  602.  
  603.     if ( worry_about_NULs && nultrans )
  604.         {
  605.         if ( ! fulltbl && ! fullspd )
  606.             /* Compressed tables back up *before* they match. */
  607.             gen_backing_up();
  608.  
  609.         indent_puts( "if ( *yy_cp )" );
  610.         indent_up();
  611.         indent_puts( "{" );    /* } for vi */
  612.         }
  613.  
  614.     if ( fulltbl )
  615.         indent_put2s(
  616.             "yy_current_state = yy_nxt[yy_current_state][%s];", 
  617.                 char_map );
  618.  
  619.     else if ( fullspd )
  620.         indent_put2s(
  621.             "yy_current_state += yy_current_state[%s].yy_nxt;",
  622.                 char_map );
  623.  
  624.     else
  625.         gen_next_compressed_state( char_map );
  626.  
  627.     if ( worry_about_NULs && nultrans )
  628.         {
  629.         /* { for vi */
  630.         indent_puts( "}" );
  631.         indent_down();
  632.         indent_puts( "else" );
  633.         indent_up();
  634.         indent_puts(
  635.             "yy_current_state = yy_NUL_trans[yy_current_state];" );
  636.         indent_down();
  637.         }
  638.  
  639.     if ( fullspd || fulltbl )
  640.         gen_backing_up();
  641.  
  642.     if ( reject )
  643.         indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  644.     }
  645.  
  646.  
  647. /* Generate the code to make a NUL transition. */
  648.  
  649. void gen_NUL_trans()
  650.     { /* NOTE - changes in here should be reflected in get_next_match() */
  651.     int need_backing_up = (num_backing_up > 0 && ! reject);
  652.  
  653.     if ( need_backing_up )
  654.         /* We'll need yy_cp lying around for the gen_backing_up(). */
  655.         indent_puts( "register char *yy_cp = yy_c_buf_p;" );
  656.  
  657.     putchar( '\n' );
  658.  
  659.     if ( nultrans )
  660.         {
  661.         indent_puts(
  662.             "yy_current_state = yy_NUL_trans[yy_current_state];" );
  663.         indent_puts( "yy_is_jam = (yy_current_state == 0);" );
  664.         }
  665.  
  666.     else if ( fulltbl )
  667.         {
  668.         do_indent();
  669.         printf( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
  670.             NUL_ec );
  671.         indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
  672.         }
  673.  
  674.     else if ( fullspd )
  675.         {
  676.         do_indent();
  677.         printf( "register int yy_c = %d;\n", NUL_ec );
  678.  
  679.         indent_puts(
  680.         "register const struct yy_trans_info *yy_trans_info;\n" );
  681.         indent_puts(
  682.         "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" );
  683.         indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  684.  
  685.         indent_puts(
  686.             "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
  687.         }
  688.  
  689.     else
  690.         {
  691.         char NUL_ec_str[20];
  692.  
  693.         (void) sprintf( NUL_ec_str, "%d", NUL_ec );
  694.         gen_next_compressed_state( NUL_ec_str );
  695.  
  696.         if ( reject )
  697.             indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  698.  
  699.         do_indent();
  700.  
  701.         printf( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
  702.         }
  703.  
  704.     /* If we've entered an accepting state, back up; note that
  705.      * compressed tables have *already* done such backing up, so
  706.      * we needn't bother with it again.
  707.      */
  708.     if ( need_backing_up && (fullspd || fulltbl) )
  709.         {
  710.         putchar( '\n' );
  711.         indent_puts( "if ( ! yy_is_jam )" );
  712.         indent_up();
  713.         indent_puts( "{" );
  714.         gen_backing_up();
  715.         indent_puts( "}" );
  716.         indent_down();
  717.         }
  718.     }
  719.  
  720.  
  721. /* Generate the code to find the start state. */
  722.  
  723. void gen_start_state()
  724.     {
  725.     if ( fullspd )
  726.         indent_put2s(
  727.             "yy_current_state = yy_start_state_list[yy_start%s];",
  728.             bol_needed ? " + (yy_bp[-1] == '\\n' ? 1 : 0)" : "" );
  729.  
  730.     else
  731.         {
  732.         indent_puts( "yy_current_state = yy_start;" );
  733.  
  734.         if ( bol_needed )
  735.             {
  736.             indent_puts( "if ( yy_bp[-1] == '\\n' )" );
  737.             indent_up();
  738.             indent_puts( "++yy_current_state;" );
  739.             indent_down();
  740.             }
  741.  
  742.         if ( reject )
  743.             {
  744.             /* Set up for storing up states. */
  745.             indent_puts( "yy_state_ptr = yy_state_buf;" );
  746.             indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  747.             }
  748.         }
  749.     }
  750.  
  751.  
  752. /* gentabs - generate data statements for the transition tables */
  753.  
  754. void gentabs()
  755.     {
  756.     int i, j, k, *accset, nacc, *acc_array, total_states;
  757.     int end_of_buffer_action = num_rules + 1;
  758.  
  759.     /* *Everything* is done in terms of arrays starting at 1, so provide
  760.      * a null entry for the zero element of all C arrays.
  761.      */
  762.     static char C_char_decl[] =
  763.         "static const YY_CHAR %s[%d] =\n    {   0,\n";    /* } for vi */
  764.  
  765.     acc_array = allocate_integer_array( current_max_dfas );
  766.     nummt = 0;
  767.  
  768.     /* The compressed table format jams by entering the "jam state",
  769.      * losing information about the previous state in the process.
  770.      * In order to recover the previous state, we effectively need
  771.      * to keep backing-up information.
  772.      */
  773.     ++num_backing_up;
  774.  
  775.     if ( reject )
  776.         {
  777.         /* Write out accepting list and pointer list.
  778.          *
  779.          * First we generate the "yy_acclist" array.  In the process,
  780.          * we compute the indices that will go into the "yy_accept"
  781.          * array, and save the indices in the dfaacc array.
  782.          */
  783.         int EOB_accepting_list[2];
  784.  
  785.         /* Set up accepting structures for the End Of Buffer state. */
  786.         EOB_accepting_list[0] = 0;
  787.         EOB_accepting_list[1] = end_of_buffer_action;
  788.         accsiz[end_of_buffer_state] = 1;
  789.         dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
  790.  
  791.         printf( long_align ? C_long_decl : C_short_decl,
  792.             "yy_acclist", MAX( numas, 1 ) + 1 );
  793.  
  794.         j = 1;    /* index into "yy_acclist" array */
  795.  
  796.         for ( i = 1; i <= lastdfa; ++i )
  797.             {
  798.             acc_array[i] = j;
  799.  
  800.             if ( accsiz[i] != 0 )
  801.                 {
  802.                 accset = dfaacc[i].dfaacc_set;
  803.                 nacc = accsiz[i];
  804.  
  805.                 if ( trace )
  806.                     fprintf( stderr,
  807.                         "state # %d accepts: ", i );
  808.  
  809.                 for ( k = 1; k <= nacc; ++k )
  810.                     {
  811.                     int accnum = accset[k];
  812.  
  813.                     ++j;
  814.  
  815.                     if ( variable_trailing_context_rules &&
  816.                       ! (accnum & YY_TRAILING_HEAD_MASK) &&
  817.                        accnum > 0 && accnum <= num_rules &&
  818.                       rule_type[accnum] == RULE_VARIABLE )
  819.                         {
  820.                         /* Special hack to flag
  821.                          * accepting number as part
  822.                          * of trailing context rule.
  823.                          */
  824.                         accnum |= YY_TRAILING_MASK;
  825.                         }
  826.  
  827.                     mkdata( accnum );
  828.  
  829.                     if ( trace )
  830.                         {
  831.                         fprintf( stderr, "[%d]",
  832.                             accset[k] );
  833.  
  834.                         if ( k < nacc )
  835.                             fputs( ", ", stderr );
  836.                         else
  837.                             putc( '\n', stderr );
  838.                         }
  839.                     }
  840.                 }
  841.             }
  842.  
  843.         /* add accepting number for the "jam" state */
  844.         acc_array[i] = j;
  845.  
  846.         dataend();
  847.         }
  848.  
  849.     else
  850.         {
  851.         dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  852.  
  853.         for ( i = 1; i <= lastdfa; ++i )
  854.             acc_array[i] = dfaacc[i].dfaacc_state;
  855.  
  856.         /* add accepting number for jam state */
  857.         acc_array[i] = 0;
  858.         }
  859.  
  860.     /* Spit out "yy_accept" array.  If we're doing "reject", it'll be
  861.      * pointers into the "yy_acclist" array.  Otherwise it's actual
  862.      * accepting numbers.  In either case, we just dump the numbers.
  863.      */
  864.  
  865.     /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
  866.      * beginning at 0 and for "jam" state.
  867.      */
  868.     k = lastdfa + 2;
  869.  
  870.     if ( reject )
  871.         /* We put a "cap" on the table associating lists of accepting
  872.          * numbers with state numbers.  This is needed because we tell
  873.          * where the end of an accepting list is by looking at where
  874.          * the list for the next state starts.
  875.          */
  876.         ++k;
  877.  
  878.     printf( long_align ? C_long_decl : C_short_decl, "yy_accept", k );
  879.  
  880.     for ( i = 1; i <= lastdfa; ++i )
  881.         {
  882.         mkdata( acc_array[i] );
  883.  
  884.         if ( ! reject && trace && acc_array[i] )
  885.             fprintf( stderr, "state # %d accepts: [%d]\n",
  886.                 i, acc_array[i] );
  887.         }
  888.  
  889.     /* Add entry for "jam" state. */
  890.     mkdata( acc_array[i] );
  891.  
  892.     if ( reject )
  893.         /* Add "cap" for the list. */
  894.         mkdata( acc_array[i] );
  895.  
  896.     dataend();
  897.  
  898.     if ( useecs )
  899.         genecs();
  900.  
  901.     if ( usemecs )
  902.         {
  903.         /* Write out meta-equivalence classes (used to index
  904.          * templates with).
  905.          */
  906.  
  907.         if ( trace )
  908.             fputs( "\n\nMeta-Equivalence Classes:\n", stderr );
  909.  
  910.         printf( C_int_decl, "yy_meta", numecs + 1 );
  911.  
  912.         for ( i = 1; i <= numecs; ++i )
  913.             {
  914.             if ( trace )
  915.                 fprintf( stderr, "%d = %d\n",
  916.                     i, ABS( tecbck[i] ) );
  917.  
  918.             mkdata( ABS( tecbck[i] ) );
  919.             }
  920.  
  921.         dataend();
  922.         }
  923.  
  924.     total_states = lastdfa + numtemps;
  925.  
  926.     printf( (tblend >= MAX_SHORT || long_align) ?
  927.             C_long_decl : C_short_decl,
  928.         "yy_base", total_states + 1 );
  929.  
  930.     for ( i = 1; i <= lastdfa; ++i )
  931.         {
  932.         register int d = def[i];
  933.  
  934.         if ( base[i] == JAMSTATE )
  935.             base[i] = jambase;
  936.  
  937.         if ( d == JAMSTATE )
  938.             def[i] = jamstate;
  939.  
  940.         else if ( d < 0 )
  941.             {
  942.             /* Template reference. */
  943.             ++tmpuses;
  944.             def[i] = lastdfa - d + 1;
  945.             }
  946.  
  947.         mkdata( base[i] );
  948.         }
  949.  
  950.     /* Generate jam state's base index. */
  951.     mkdata( base[i] );
  952.  
  953.     for ( ++i /* skip jam state */; i <= total_states; ++i )
  954.         {
  955.         mkdata( base[i] );
  956.         def[i] = jamstate;
  957.         }
  958.  
  959.     dataend();
  960.  
  961.     printf( (total_states >= MAX_SHORT || long_align) ?
  962.             C_long_decl : C_short_decl,
  963.         "yy_def", total_states + 1 );
  964.  
  965.     for ( i = 1; i <= total_states; ++i )
  966.         mkdata( def[i] );
  967.  
  968.     dataend();
  969.  
  970.     printf( (total_states >= MAX_SHORT || long_align) ?
  971.             C_long_decl : C_short_decl,
  972.         "yy_nxt", tblend + 1 );
  973.  
  974.     for ( i = 1; i <= tblend; ++i )
  975.         {
  976.         if ( nxt[i] == 0 || chk[i] == 0 )
  977.             nxt[i] = jamstate;    /* new state is the JAM state */
  978.  
  979.         mkdata( nxt[i] );
  980.         }
  981.  
  982.     dataend();
  983.  
  984.     printf( (total_states >= MAX_SHORT || long_align) ?
  985.             C_long_decl : C_short_decl,
  986.         "yy_chk", tblend + 1 );
  987.  
  988.     for ( i = 1; i <= tblend; ++i )
  989.         {
  990.         if ( chk[i] == 0 )
  991.             ++nummt;
  992.  
  993.         mkdata( chk[i] );
  994.         }
  995.  
  996.     dataend();
  997.     }
  998.  
  999.  
  1000. /* Write out a formatted string (with a secondary string argument) at the
  1001.  * current indentation level, adding a final newline.
  1002.  */
  1003.  
  1004. void indent_put2s( fmt, arg )
  1005. char fmt[], arg[];
  1006.     {
  1007.     do_indent();
  1008.     printf( fmt, arg );
  1009.     putchar( '\n' );
  1010.     }
  1011.  
  1012.  
  1013. /* Write out a string at the current indentation level, adding a final
  1014.  * newline.
  1015.  */
  1016.  
  1017. void indent_puts( str )
  1018. char str[];
  1019.     {
  1020.     do_indent();
  1021.     puts( str );
  1022.     }
  1023.  
  1024.  
  1025. /* make_tables - generate transition tables and finishes generating output file
  1026.  */
  1027.  
  1028. void make_tables()
  1029.     {
  1030.     register int i;
  1031.     int did_eof_rule = false;
  1032.  
  1033.     skelout();
  1034.  
  1035.     /* First, take care of YY_DO_BEFORE_ACTION depending on yymore
  1036.      * being used.
  1037.      */
  1038.     set_indent( 1 );
  1039.  
  1040.     if ( yymore_used )
  1041.         {
  1042.         indent_puts( "yytext_ptr -= yy_more_len; \\" );
  1043.         indent_puts( "yyleng = yy_cp - yytext_ptr; \\" );
  1044.         }
  1045.  
  1046.     else
  1047.         indent_puts( "yyleng = yy_cp - yy_bp; \\" );
  1048.  
  1049.     /* Now also deal with copying yytext_ptr to yytext if needed. */
  1050.     skelout();
  1051.     if ( yytext_is_array )
  1052.         {
  1053.         indent_puts( "if ( yyleng >= YYLMAX ) \\" );
  1054.         indent_up();
  1055.         indent_puts(
  1056.         "YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" );
  1057.         indent_down();
  1058.         indent_puts(
  1059.         "yy_flex_strncpy( yytext, yytext_ptr, yyleng + 1 ); \\" );
  1060.         }
  1061.  
  1062.     set_indent( 0 );
  1063.  
  1064.     skelout();
  1065.  
  1066.  
  1067.     printf( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
  1068.  
  1069.     if ( fullspd )
  1070.         {
  1071.         /* Need to define the transet type as a size large
  1072.          * enough to hold the biggest offset.
  1073.          */
  1074.         int total_table_size = tblend + numecs + 1;
  1075.         char *trans_offset_type =
  1076.             (total_table_size >= MAX_SHORT || long_align) ?
  1077.                 "long" : "short";
  1078.  
  1079.         set_indent( 0 );
  1080.         indent_puts( "struct yy_trans_info" );
  1081.         indent_up();
  1082.         indent_puts( "{" );     /* } for vi */
  1083.  
  1084.         if ( long_align )
  1085.             indent_puts( "long yy_verify;" );
  1086.         else
  1087.             indent_puts( "short yy_verify;" );
  1088.  
  1089.         /* In cases where its sister yy_verify *is* a "yes, there is
  1090.          * a transition", yy_nxt is the offset (in records) to the
  1091.          * next state.  In most cases where there is no transition,
  1092.          * the value of yy_nxt is irrelevant.  If yy_nxt is the -1th
  1093.          * record of a state, though, then yy_nxt is the action number
  1094.          * for that state.
  1095.          */
  1096.  
  1097.         indent_put2s( "%s yy_nxt;", trans_offset_type );
  1098.         indent_puts( "};" );
  1099.         indent_down();
  1100.         }
  1101.  
  1102.     if ( fullspd )
  1103.         genctbl();
  1104.     else if ( fulltbl )
  1105.         genftbl();
  1106.     else
  1107.         gentabs();
  1108.  
  1109.     /* Definitions for backing up.  We don't need them if REJECT
  1110.      * is being used because then we use an alternative backin-up
  1111.      * technique instead.
  1112.      */
  1113.     if ( num_backing_up > 0 && ! reject )
  1114.         {
  1115.         if ( ! C_plus_plus )
  1116.             {
  1117.             indent_puts(
  1118.             "static yy_state_type yy_last_accepting_state;" );
  1119.             indent_puts(
  1120.                 "static char *yy_last_accepting_cpos;\n" );
  1121.             }
  1122.         }
  1123.  
  1124.     if ( nultrans )
  1125.         {
  1126.         printf( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
  1127.  
  1128.         for ( i = 1; i <= lastdfa; ++i )
  1129.             {
  1130.             if ( fullspd )
  1131.                 printf( "    &yy_transition[%d],\n", base[i] );
  1132.             else
  1133.                 mkdata( nultrans[i] );
  1134.             }
  1135.  
  1136.         dataend();
  1137.         }
  1138.  
  1139.     if ( ddebug )
  1140.         { /* Spit out table mapping rules to line numbers. */
  1141.         indent_puts( "extern int yy_flex_debug;" );
  1142.         indent_puts( "int yy_flex_debug = 1;\n" );
  1143.  
  1144.         printf( long_align ? C_long_decl : C_short_decl,
  1145.             "yy_rule_linenum", num_rules );
  1146.         for ( i = 1; i < num_rules; ++i )
  1147.             mkdata( rule_linenum[i] );
  1148.         dataend();
  1149.         }
  1150.  
  1151.     if ( reject )
  1152.         {
  1153.         /* Declare state buffer variables. */
  1154.         if ( ! C_plus_plus )
  1155.             {
  1156.             puts(
  1157.     "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
  1158.             puts( "static char *yy_full_match;" );
  1159.             puts( "static int yy_lp;" );
  1160.             }
  1161.  
  1162.         if ( variable_trailing_context_rules )
  1163.             {
  1164.             if ( ! C_plus_plus )
  1165.                 {
  1166.                 puts(
  1167.                 "static int yy_looking_for_trail_begin = 0;" );
  1168.                 puts( "static int yy_full_lp;" );
  1169.                 puts( "static int *yy_full_state;" );
  1170.                 }
  1171.  
  1172.             printf( "#define YY_TRAILING_MASK 0x%x\n",
  1173.                 (unsigned int) YY_TRAILING_MASK );
  1174.             printf( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
  1175.                 (unsigned int) YY_TRAILING_HEAD_MASK );
  1176.             }
  1177.  
  1178.         puts( "#define REJECT \\" );
  1179.         puts( "{ \\" );        /* } for vi */
  1180.         puts(
  1181.     "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
  1182.         puts(
  1183.     "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
  1184.  
  1185.         if ( variable_trailing_context_rules )
  1186.             {
  1187.             puts(
  1188.         "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
  1189.             puts(
  1190.         "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
  1191.             puts(
  1192.     "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
  1193.             }
  1194.  
  1195.         puts( "++yy_lp; \\" );
  1196.         puts( "goto find_rule; \\" );
  1197.         /* { for vi */
  1198.         puts( "}" );
  1199.         }
  1200.  
  1201.     else
  1202.         {
  1203.         puts(
  1204.         "/* The intent behind this definition is that it'll catch" );
  1205.         puts( " * any uses of REJECT which flex missed." );
  1206.         puts( " */" );
  1207.         puts( "#define REJECT reject_used_but_not_detected" );
  1208.         }
  1209.  
  1210.     if ( yymore_used )
  1211.         {
  1212.         if ( ! C_plus_plus )
  1213.             {
  1214.             indent_puts( "static int yy_more_flag = 0;" );
  1215.             indent_puts( "static int yy_more_len = 0;" );
  1216.             }
  1217.  
  1218.         indent_puts( "#define yymore() (yy_more_flag = 1)" );
  1219.         indent_puts( "#define YY_MORE_ADJ yy_more_len" );
  1220.         }
  1221.  
  1222.     else
  1223.         {
  1224.         indent_puts( "#define yymore() yymore_used_but_not_detected" );
  1225.         indent_puts( "#define YY_MORE_ADJ 0" );
  1226.         }
  1227.  
  1228.     if ( ! C_plus_plus )
  1229.         {
  1230.         if ( yytext_is_array )
  1231.             {
  1232.             puts( "#ifndef YYLMAX" );
  1233.             puts( "#define YYLMAX 8192" );
  1234.             puts( "#endif\n" );
  1235.             puts( "char yytext[YYLMAX];" );
  1236.             puts( "char *yytext_ptr;" );
  1237.             }
  1238.  
  1239.         else
  1240.             puts( "char *yytext;" );
  1241.         }
  1242.  
  1243.     fputs( &action_array[defs1_offset], stdout );
  1244.  
  1245.     skelout();
  1246.  
  1247.     if ( ! C_plus_plus )
  1248.         {
  1249.         if ( use_read )
  1250.             {
  1251.             printf(
  1252. "\tif ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\\n" );
  1253.             printf(
  1254.         "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );\n" );
  1255.             }
  1256.  
  1257.         else
  1258.             {
  1259.             printf(
  1260.             "\tif ( yy_current_buffer->yy_is_interactive ) \\\n" );
  1261.             printf( "\t\t{ \\\n" );
  1262.             printf( "\t\tint c = getc( yyin ); \\\n" );
  1263.             printf( "\t\tresult = c == EOF ? 0 : 1; \\\n" );
  1264.             printf( "\t\tbuf[0] = (char) c; \\\n" );
  1265.             printf( "\t\t} \\\n" );
  1266.             printf(
  1267.     "\telse if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \\\n" );
  1268.             printf( "\t\t  && ferror( yyin ) ) \\\n" );
  1269.             printf(
  1270.         "\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" );\n" );
  1271.             }
  1272.         }
  1273.  
  1274.     skelout();
  1275.  
  1276.     /* Copy prolog to output file. */
  1277.     fputs( &action_array[prolog_offset], stdout );
  1278.  
  1279.     skelout();
  1280.  
  1281.     set_indent( 2 );
  1282.  
  1283.     if ( yymore_used )
  1284.         {
  1285.         indent_puts( "yy_more_len = 0;" );
  1286.         indent_puts( "if ( yy_more_flag )" );
  1287.         indent_up();
  1288.         indent_puts( "{" );
  1289.         indent_puts( "yy_more_len = yyleng;" );
  1290.         indent_puts( "yy_more_flag = 0;" );
  1291.         indent_puts( "}" );
  1292.         indent_down();
  1293.         }
  1294.  
  1295.     skelout();
  1296.  
  1297.     gen_start_state();
  1298.  
  1299.     /* Note, don't use any indentation. */
  1300.     puts( "yy_match:" );
  1301.     gen_next_match();
  1302.  
  1303.     skelout();
  1304.     set_indent( 2 );
  1305.     gen_find_action();
  1306.  
  1307.     skelout();
  1308.     if ( lex_compat )
  1309.         {
  1310.         indent_puts( "if ( yy_act != YY_END_OF_BUFFER )" );
  1311.         indent_up();
  1312.         indent_puts( "{" );
  1313.         indent_puts( "int yyl;" );
  1314.         indent_puts( "for ( yyl = 0; yyl < yyleng; ++yyl )" );
  1315.         indent_up();
  1316.         indent_puts( "if ( yytext[yyl] == '\\n' )" );
  1317.         indent_up();
  1318.         indent_puts( "++yylineno;" );
  1319.         indent_down();
  1320.         indent_down();
  1321.         indent_puts( "}" );
  1322.         indent_down();
  1323.         }
  1324.  
  1325.     skelout();
  1326.     if ( ddebug )
  1327.         {
  1328.         indent_puts( "if ( yy_flex_debug )" );
  1329.         indent_up();
  1330.  
  1331.         indent_puts( "{" );
  1332.         indent_puts( "if ( yy_act == 0 )" );
  1333.         indent_up();
  1334.         indent_puts(
  1335.             "fprintf( stderr, \"--scanner backing up\\n\" );" );
  1336.         indent_down();
  1337.  
  1338.         do_indent();
  1339.         printf( "else if ( yy_act < %d )\n", num_rules );
  1340.         indent_up();
  1341.         indent_puts(
  1342.     "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
  1343.         indent_puts( "         yy_rule_linenum[yy_act], yytext );" );
  1344.         indent_down();
  1345.  
  1346.         do_indent();
  1347.         printf( "else if ( yy_act == %d )\n", num_rules );
  1348.         indent_up();
  1349.         indent_puts(
  1350.     "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
  1351.         indent_puts( "         yytext );" );
  1352.         indent_down();
  1353.  
  1354.         do_indent();
  1355.         printf( "else if ( yy_act == %d )\n", num_rules + 1 );
  1356.         indent_up();
  1357.         indent_puts(
  1358.     "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
  1359.         indent_down();
  1360.  
  1361.         do_indent();
  1362.         printf( "else\n" );
  1363.         indent_up();
  1364.         indent_puts(
  1365.     "fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" );
  1366.         indent_down();
  1367.  
  1368.         indent_puts( "}" );
  1369.         indent_down();
  1370.         }
  1371.  
  1372.     /* Copy actions to output file. */
  1373.     skelout();
  1374.     indent_up();
  1375.     gen_bu_action();
  1376.     fputs( &action_array[action_offset], stdout );
  1377.  
  1378.     /* generate cases for any missing EOF rules */
  1379.     for ( i = 1; i <= lastsc; ++i )
  1380.         if ( ! sceof[i] )
  1381.             {
  1382.             do_indent();
  1383.             printf( "case YY_STATE_EOF(%s):\n", scname[i] );
  1384.             did_eof_rule = true;
  1385.             }
  1386.  
  1387.     if ( did_eof_rule )
  1388.         {
  1389.         indent_up();
  1390.         indent_puts( "yyterminate();" );
  1391.         indent_down();
  1392.         }
  1393.  
  1394.  
  1395.     /* Generate code for handling NUL's, if needed. */
  1396.  
  1397.     /* First, deal with backing up and setting up yy_cp if the scanner
  1398.      * finds that it should JAM on the NUL.
  1399.      */
  1400.     skelout();
  1401.     set_indent( 7 );
  1402.  
  1403.     if ( fullspd || fulltbl )
  1404.         indent_puts( "yy_cp = yy_c_buf_p;" );
  1405.  
  1406.     else
  1407.         { /* compressed table */
  1408.         if ( ! reject && ! interactive )
  1409.             {
  1410.             /* Do the guaranteed-needed backing up to figure
  1411.              * out the match.
  1412.              */
  1413.             indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  1414.             indent_puts(
  1415.                 "yy_current_state = yy_last_accepting_state;" );
  1416.             }
  1417.  
  1418.         else
  1419.             /* Still need to initialize yy_cp, though
  1420.              * yy_current_state was set up by
  1421.              * yy_get_previous_state().
  1422.              */
  1423.             indent_puts( "yy_cp = yy_c_buf_p;" );
  1424.         }
  1425.  
  1426.  
  1427.     /* Generate code for yy_get_previous_state(). */
  1428.     set_indent( 1 );
  1429.     skelout();
  1430.  
  1431.     if ( bol_needed )
  1432.         indent_puts( "register char *yy_bp = yytext_ptr;\n" );
  1433.  
  1434.     gen_start_state();
  1435.  
  1436.     set_indent( 2 );
  1437.     skelout();
  1438.     gen_next_state( true );
  1439.  
  1440.     set_indent( 1 );
  1441.     skelout();
  1442.     gen_NUL_trans();
  1443.  
  1444.     skelout();
  1445.     if ( lex_compat )
  1446.         { /* update yylineno inside of unput() */
  1447.         indent_puts( "if ( c == '\\n' )" );
  1448.         indent_up();
  1449.         indent_puts( "--yylineno;" );
  1450.         indent_down();
  1451.         }
  1452.  
  1453.     skelout();
  1454.  
  1455.     /* Copy remainder of input to output. */
  1456.  
  1457.     line_directive_out( stdout );
  1458.  
  1459.     if ( sectnum == 3 )
  1460.         (void) flexscan(); /* copy remainder of input to output */
  1461.     }
  1462.